package blackberry.util;

import net.rim.device.api.applicationcontrol.ApplicationPermissions;
import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;

public class DjPermissions {
	private static final ApplicationPermissionsManager permissionsManager = 
			ApplicationPermissionsManager.getInstance();
	
	public static void invokePermissionsRequest(int [] permissions) {
		ApplicationPermissions appPermissions = new ApplicationPermissions();
		for (int i = 0; i < permissions.length; i++){
			appPermissions.addPermission(permissions[i]);
		}
		permissionsManager.invokePermissionsRequest(appPermissions);
	}
	
	public static boolean isDenyPermissions(int[] permissions){
		return (getDenyPermissions(permissions).getPermissionKeys().length > 0) ? true : false;
	}
	private static ApplicationPermissions getDenyPermissions(int[] permissions) {
		ApplicationPermissions appPermission = new ApplicationPermissions();
		for (int i = 0; i < permissions.length; i++) {
			if (permissionsManager.getApplicationPermissions()
					.getPermission(permissions[i]) != ApplicationPermissions.VALUE_ALLOW) {
				appPermission.addPermission(permissions[i]);
			}
		}
		return appPermission;
	}
	
	public static int[] getAllPermissions(){
		return new int[]{
				ApplicationPermissions.PERMISSION_APPLICATION_MANAGEMENT,
				ApplicationPermissions.PERMISSION_AUTHENTICATOR_API,
				ApplicationPermissions.PERMISSION_BLUETOOTH,
				ApplicationPermissions.PERMISSION_BROWSER_FILTER,
				ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION,
				ApplicationPermissions.PERMISSION_DEVICE_SETTINGS,
				ApplicationPermissions.PERMISSION_DISPLAY_LOCKED,
				ApplicationPermissions.PERMISSION_EMAIL,
				ApplicationPermissions.PERMISSION_FILE_API,
				ApplicationPermissions.PERMISSION_IDLE_TIMER,
				ApplicationPermissions.PERMISSION_INPUT_SIMULATION,
				ApplicationPermissions.PERMISSION_INTERNET,
				ApplicationPermissions.PERMISSION_LOCATION_DATA,
				ApplicationPermissions.PERMISSION_MEDIA,
				ApplicationPermissions.PERMISSION_ORGANIZER_DATA,
				ApplicationPermissions.PERMISSION_PHONE,
				ApplicationPermissions.PERMISSION_RECORDING,
				ApplicationPermissions.PERMISSION_SERVER_NETWORK,
				ApplicationPermissions.PERMISSION_THEMES,
				ApplicationPermissions.PERMISSION_USB,
				ApplicationPermissions.PERMISSION_WIFI,
				ApplicationPermissions.PERMISSION_CHANGE_DEVICE_SETTINGS,
				ApplicationPermissions.PERMISSION_CODE_MODULE_MANAGEMENT,
				ApplicationPermissions.PERMISSION_EVENT_INJECTOR,
				ApplicationPermissions.PERMISSION_EXTERNAL_CONNECTIONS,
				ApplicationPermissions.PERMISSION_HANDHELD_KEYSTORE,
				ApplicationPermissions.PERMISSION_INTER_PROCESS_COMMUNICATION,
				ApplicationPermissions.PERMISSION_INTERNAL_CONNECTIONS,
				ApplicationPermissions.PERMISSION_LOCAL_CONNECTIONS,
				ApplicationPermissions.PERMISSION_LOCATION_API,
				ApplicationPermissions.PERMISSION_PIM,
				ApplicationPermissions.PERMISSION_SCREEN_CAPTURE,
				ApplicationPermissions.PERMISSION_THEME_DATA,
/**	9700에서 	ApplicationPermissions.PERMISSION_NFC,    					  */
/** 그냥안됬음	ApplicationPermissions.PERMISSION_KEYSTORE_MEDIUM_SECURITY,  
				ApplicationPermissions.PERMISSION_SECURE_ELEMENT,
				ApplicationPermissions.PERMISSION_SECURITY_DATA, 			  */
		};
	}
}